using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace SmokeAlarm
{
    public partial class Splash : Form
    {
        // Threading
        static Splash ms_frmSplash = null;
        //static Thread ms_oThread = null; This was originally a threaded app, but since I hacked the Input box to thread it...no need at the moment.

        // Fade in and out.
        private double m_dblOpacityIncrement = .05;
        private double m_dblOpacityDecrement = .08;
        private const int TIMER_INTERVAL = 50;

        public Splash()
        {
            //Fade Initialization

            InitializeComponent();

            //Initialize variables for progress bar and fading.
            this.Opacity = .0;
            timer1.Interval = TIMER_INTERVAL;
            timer1.Start();
            timer2.Start();
            progressBar1.Maximum = 400;
            progressBar1.Minimum = 0;
            progressBar1.Step = 30;
        }
        static public void ShowSplashScreen()
        {
            // Make sure it is only launched once.
            if (ms_frmSplash != null)
                return;
            Splash.ShowForm();

        }


        // A static entry point to launch SplashScreen.
        static private void ShowForm()
        {

                //ms_frmSplash = new Splash();
               //Application.Run(ms_frmSplash);

        }

        private void Splash_Load(object sender, EventArgs e)
        {

        }

        static public void CloseForm()
        {
            if (ms_frmSplash != null)
            {
                // Make it start going away.
                ms_frmSplash.m_dblOpacityIncrement = -ms_frmSplash.m_dblOpacityDecrement;
            }
            //ms_oThread = null;  // we do not need these any more.
            ms_frmSplash = null;
        }

        private void timer1_Tick_1(object sender, EventArgs e)
        {
          

            if (m_dblOpacityIncrement > 0)
            {
                if (this.Opacity < 1)
                    this.Opacity += m_dblOpacityIncrement;
            }
            else
            {
                if (this.Opacity > 0)
                    this.Opacity += m_dblOpacityIncrement;
                else
                    this.Close();
            }
        }


        private void timer2_Tick(object sender, EventArgs e)
        {
            if (progressBar1.Value >= 400)
            {
                progressBar1.Value = 400;
            }
            else
            {
                progressBar1.Value += 20;
            }
        }

        private void progressBar1_Click(object sender, EventArgs e)
        {
            this.Close();
        }




    }
}